package org.zhenglide.oa.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.zhenglide.oa.entity.Employee;
import org.zhenglide.oa.service.IEmployeeService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

@Controller
public class LoginController {
	@Autowired
	IEmployeeService employeeService;
	@RequestMapping("/login")
	public String login()
	{
		return "login";
	}
	@RequestMapping("/doLogin")
	public String doLogin(@RequestParam(value="name") String name , HttpServletRequest req)
	{
		Employee employee = employeeService.getOne(new QueryWrapper<Employee>().eq("name", name));
		if ( null != employee){
			req.getSession().setAttribute("employee", employee);
			return "redirect:/home";
		}	
		
		return "redirect:/login";
	}
	@RequestMapping("/logout")
	public String logout(HttpServletRequest req)
	{
		req.getSession().removeAttribute("employee");
		return "redirect:/login";
	}
	@RequestMapping("/home")
	public String main(Model model)
	{
		return "main";
	}
	@RequestMapping("/top")
	public String top()
	{
		return "top";
	}
	@RequestMapping("/left")
	public String left()
	{
		return "left";
	}
	@RequestMapping("/welcome")
	public String welcome()
	{
		return "welcome";
	}
	
}
